<?php


namespace app\index\controller;


use app\common\controller\AdminController;
use app\common\controller\UserController;
use app\common\model\Employ;
use app\common\model\EmployPurchase;
use app\common\model\EmployPurchaseOrder;
use app\common\model\Model;
use app\common\model\Server;
use app\common\model\ServerGood;
use app\common\model\ServerOrder;
use app\common\model\UserMoney;

class Admin extends AdminController
{
    /**
     * 获取雇主
     */
    function employ(){
        $data = Employ::simpleList();
        $this->result_success($data);
    }


    /**
     * 获取服务商
     */
    function server(){
        $data = Server::simpleList();
        $this->result_success($data);
    }


    /**
     * 获取服务商
     */
    function user(){
        $data = \app\common\model\User::simpleList();
        $this->result_success($data);
    }

    /**
     * 获取 服务
     */
    function server_good(){
        $data = ServerGood::simpleList();
        $this->result_success($data);
    }

    /**
     * 获取 服务订单
     */
    function server_order(){
        $data = ServerOrder::simpleList();
        $this->result_success($data);
    }

    /**
     * 获取 需求
     */
    function employ_purchase(){
        $data = EmployPurchase::simpleList();
        $this->result_success($data);
    }


    /**
     * 获取 需求订单
     */
    function employ_purchase_order(){
        $data = EmployPurchaseOrder::simpleList();
        $this->result_success($data);
    }

    /**
     * 获取 财务
     */
    function payment(){
        $data = \app\common\model\Payment::simpleList();
        $this->result_success($data);
    }

    /**
     * 获取 余额
     */
    function money(){
        $data = UserMoney::simpleList([
            "result"=>function(&$row){
                $user = \app\common\model\User::getById($row["uid"]);
                if($user){
                    $user = $user->toArray();
                    $row = array_merge($row,$user);
                }else{
                    UserMoney::simpleDelete(function(Model $query)use($row){
                        $query->where("id",$row["id"]);
                    });
                }
            }
        ]);
        $this->result_success($data);
    }



}